package org.flexspeedup.blog.commands
{
import mx.collections.ArrayList;
import mx.collections.IList;

import org.flexspeedup.model.ListOption;
import org.flexspeedup.model.Settings;
import org.swizframework.utils.chain.CommandChainStep;

/**
 * This command looks for category listings in the settings file and parses them
 */
public class ParsePostingCategoriesCommand extends CommandChainStep
{

    //--------------------------------------------------------------------------
    //
    // Constructor
    //
    //--------------------------------------------------------------------------

    /**
     * Creates a new <code>ParsePostingCategoriesCommand</code> instance.
     */
    public function ParsePostingCategoriesCommand()
    {
        super();
    }

    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    // categoryList
    //----------------------------------
    [Bindable]
    /**
     * The parsed categories.
     */
    public var categoryList:IList;
   
    //----------------------------------
    // settings
    //----------------------------------
    [Inject(source="settings")]
    /**
     * settings bean
     */
    public var settings:Settings;

    //--------------------------------------------------------------------------
    //
    //  Overridden Methods - ChainStepCommand
    //
    //--------------------------------------------------------------------------
    
    override public function execute():void
    {
        var categories:Array = [];
        for each (var category:XML in XML(settings.postingCategories).category)
            categories.push(new ListOption(category.@id, category));
        categoryList = new ArrayList(categories);
        complete();
    }
    
}
}